package com.naiterui.ehp.bs.esign.controller.inner;

import com.naiterui.ehp.bp.bo.esign.PreSignResultBO;
import com.naiterui.ehp.bp.bo.esign.RecomSignParamBO;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.esign.exception.ExceptionCodes;
import com.naiterui.ehp.bs.esign.service.IRecomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guoyongxiang
 * @date 2019/12/3 18:02
 * @since 1.0.0
 */
@RequestMapping("esign/inner/recom")
@RestController
public class EsignInnerRecomController {

    private static final Logger LOGGER = LoggerFactory.getLogger(EsignInnerRecomController.class);

    @Autowired
    private IRecomService recomService;


    /**
     * 医师处方预签署
     *
     * @param RecomSignParamBO
     *
     * @return
     *
     * @throws BusinessException
     */
    @PostMapping("preSign/dr")
    public ResponseVO<PreSignResultBO> preSignDr(@RequestBody RecomSignParamBO RecomSignParamBO) throws BusinessException {
        LOGGER.info("医生处方预签署：RecomSignParamBO={}", RecomSignParamBO.toString());
        PreSignResultBO bo = recomService.preSignRecipelDr(RecomSignParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, bo);
    }

    /**
     * 药师处方预签署
     *
     * @param signParamBO
     *
     * @return
     *
     * @throws BusinessException
     */
    @PostMapping("preSign/ph")
    public ResponseVO<PreSignResultBO> preSignPh(@RequestBody RecomSignParamBO signParamBO) throws BusinessException {
        LOGGER.info("药师处方预签署：RecomSignParamBO={}", signParamBO.toString());
        PreSignResultBO bo = recomService.preSignRecipelPh(signParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, bo);
    }

    /**
     * <pre>
     *     服务端签名:e签宝签名由服务端发起
     *     异步执行
     * </pre>
     *
     *
     * @return
     *
     * @throws BusinessException
     */
    @PostMapping("sign/dr")
    public ResponseVO<Void> signDr(@RequestBody RecomSignParamBO signParamBO) throws BusinessException {
        LOGGER.info("处方医师签名开始 signVO:{}", signParamBO.toString());
        recomService.signDr(signParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    @PostMapping("sign/ph")
    public ResponseVO<Void> signPh(@RequestBody RecomSignParamBO signParamBO) throws BusinessException {
        LOGGER.info("处方药师签名开始 signVO:{}", signParamBO.toString());
        recomService.signPh(signParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    /**
     * 调配药师处方预签署
     */
    @PostMapping("preSign/al/ph")
    public ResponseVO<PreSignResultBO> preSignAlPh(@RequestBody RecomSignParamBO signParamBO) throws BusinessException {
        LOGGER.info("调配药师处方预签署：RecomSignParamBO={}", signParamBO.toString());
        PreSignResultBO bo = recomService.preSignRecipelAlPh(signParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, bo);
    }

    /**
     * 调配药师处方签名
     */
    @PostMapping("sign/al/ph")
    public ResponseVO<Void> signAlPh(@RequestBody RecomSignParamBO signParamBO) throws BusinessException {
        LOGGER.info("调配处方药师签名开始 signVO:{}", signParamBO.toString());
        recomService.signAlPh(signParamBO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }
}
